import { postParam } from '@/utils/request'

export type ViolationBaseQuery = {
  entId?: string
  /** 日期类型 - y: 年; q: 季; m: 月 */
  timeType?: string
}

export type ViolationCategoryData = {
  name: string
  value: number
  piont: number
}

export type ViolationChartDataRequest = ViolationBaseQuery

export type ViolationChartDataResponse = {
  /** 处罚方式分类 */
  cffsKvs: ViolationCategoryData[]
  /** 处理对象分类 */
  cldxKvs: ViolationCategoryData[]
  /** 违规项分类 */
  wgxKvs: ViolationCategoryData[]
  /** 治理率分类 */
  zhililvKvs: ViolationCategoryData[]
}

export const colors = [
  [
    'rgba(246, 110, 44, 0.32)',
    'rgba(246, 110, 44, 1)',
    'rgba(246, 110, 44, 1)'
  ],
  [
    'rgba(255, 177, 59, 0.31)',
    'rgba(255, 177, 59, 1)',
    'rgba(255, 177, 59, 1)'
  ],
  [
    'rgba(102, 204, 170, 0.32)',
    'rgba(102, 204, 170, 1)',
    'rgba(102, 204, 170, 1)'
  ],
  [
    'rgba(43, 193, 215, 0.32)',
    'rgba(43, 193, 215, 1)',
    'rgba(43, 193, 215, 1)'
  ],
  [
    'rgba(59, 157, 255, 0.32)',
    'rgba(59, 157, 255, 1)',
    'rgba(59, 157, 255, 1)'
  ],
  [
    'rgba(126, 105, 248, 0.32)',
    'rgba(126, 105, 248, 1)',
    'rgba(126, 105, 248, 1)'
  ],
  [
    'rgba(191, 105, 248, 0.32)',
    'rgba(191, 105, 248, 1)',
    'rgba(191, 105, 248, 1)'
  ],
  [
    'rgba(248, 105, 199, 0.32)',
    'rgba(248, 105, 199, 1)',
    'rgba(248, 105, 199, 1)'
  ],
  [
    'rgba(255, 102, 102, 0.32)',
    'rgba(255, 102, 102, 1)',
    'rgba(255, 102, 102, 1)'
  ]
]

export const extraColors = [
  ['rgba(95,166,245, 0.32)', 'rgba(95,166,245,1)', 'rgba(95,166,245,1)'],
  ['rgba(246,110,44,0.32)', 'rgba(246,110,44,1)', 'rgba(246,110,44,1)'],
  ['rgba(64,230,174,0.32)', 'rgba(64,230,174,1)', 'rgba(64,230,174,1)']
]

/**
 * 根据总数计算页面
 *
 * @param totalItems
 * @param itemsPerPage
 * @returns
 */
export function calculatePages(totalItems: number, itemsPerPage: number) {
  return Math.ceil(totalItems / itemsPerPage)
}

export const rightSafeGovernTabList = [
  {
    name: '本月',
    value: 'm'
  },
  {
    name: '本季',
    value: 'q'
  },
  {
    name: '本年',
    value: 'y'
  }
]

export const categoryTabList = [
  {
    label: '处罚方式',
    value: 'cffsKvs'
  },
  {
    label: '处理对象',
    value: 'cldxKvs'
  },
  {
    label: '违规项',
    value: 'wgxKvs'
  },
  {
    label: '治理率',
    value: 'zhililvKvs'
  }
]

/**
 * 安全治理工单饼图
 *
 * @param params
 * @returns
 */
export const getViolationChartData = async (
  params: ViolationChartDataRequest
) => {
  const { data, suc, message } = await postParam<ViolationChartDataResponse>(
    '/code/api/dp2/gdbt',
    params
  )

  if (suc) {
    return data
  } else {
    Promise.reject(message)
  }
}

export type ViolationOrdrCountDataRequest = ViolationBaseQuery

export type ViolationOrdrCountDataResponse = {
  /** 工单总数 */
  allSum: number
  /** ai工单总数 */
  aiSum: number
  /** 人工处理工单总数 */
  rgSum: number
}

/**
 * 安全治理工单数量统计
 *
 * @param params
 * @returns
 */
export const getViolationOrdrCountData = async (
  params: ViolationOrdrCountDataRequest
) => {
  const { data, suc, message } =
    await postParam<ViolationOrdrCountDataResponse>('/code/api/dp2/gds', params)

  if (suc) {
    return data
  } else {
    Promise.reject(message)
  }
}

export type SecurityGovernanceRankingRequest = {
  entId: string
  /** top数量 */
  topNum: string
}

export type SecurityGovernanceRankingResponse = {
  /** 处理对象名称 */
  objNme: string
  /** 处理对象类型 - 1: 司机; 2: 车辆; 3: 企业 */
  objType: string
  /** 工单类型 - 1: 星软同步(人工); 2: 协会自建(人工); 3: AI机器人  */
  orderType: number
  /** 处理方式 */
  handleMethod: string
  /** 工单时间 - yyyy-MM-dd HH:mm:ss */
  handleDateTime: string
  /** 违规项名称 */
  violationItemName: string
}

/**
 * 安全治理工单top
 *
 * @param params
 * @returns
 */
export const getSecurityGovernanceRankingData = async (
  params: SecurityGovernanceRankingRequest
) => {
  const { data, suc, message } = await postParam<
    SecurityGovernanceRankingResponse[]
  >('/code/api/dp2/gdtop', params)

  if (suc) {
    return data
  } else {
    Promise.reject(message)
  }
}
